/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mysgoog.brown.move;

import java.util.*;

public class Evaluator
{

    public static final int

    /*
     * THREAT_BIT = 1, ATTACK_MOVE = 2, ATTACK_MOVE_GOOD_KO = 4,
     * ATTACK_MOVE_BAD_KO = 6, ATTACK_THREAT = (ATTACK_MOVE | THREAT_BIT),
     * DEFEND_MOVE = 8, DEFEND_MOVE_GOOD_KO = 10, DEFEND_MOVE_BAD_KO = 12,
     * DEFEND_THREAT = (DEFEND_MOVE | THREAT_BIT), CONNECT_MOVE = 14, CUT_MOVE =
     * 16, SEMEAI_MOVE = 18, SEMEAI_THREAT = (SEMEAI_MOVE | THREAT_BIT),
     * EXPAND_TERRITORY_MOVE = 20, EXPAND_MOYO_MOVE = 22, INVASION_MOVE = 24,
     * 
     * DRAGON_ATTACK_MOVE = 26, DRAGON_ATTACK_MOVE_GOOD_KO = 28,
     * DRAGON_ATTACK_MOVE_BAD_KO = 30, DRAGON_ATTACK_THREAT =
     * (DRAGON_ATTACK_MOVE | THREAT_BIT), DRAGON_DEFEND_MOVE = 32,
     * DRAGON_DEFEND_MOVE_GOOD_KO = 34, DRAGON_DEFEND_MOVE_BAD_KO = 36,
     * DRAGON_DEFEND_THREAT = (DRAGON_DEFEND_MOVE | THREAT_BIT),
     * DRAGON_PREVENT_THREAT = 38, UNCERTAIN_DRAGON_ATTACK = 40,
     * UNCERTAIN_DRAGON_DEFENSE = 42, STRATEGIC_ATTACK_MOVE = 44,
     * STRATEGIC_DEFEND_MOVE = 46,
     * 
     * MY_ATARI_ATARI_MOVE = 50, YOUR_ATARI_ATARI_MOVE = 52, VITAL_EYE_MOVE =
     * 54,
     * 
     * DRAGON_ATTACK_MOVE_GAIN = 60, DRAGON_DEFEND_MOVE_LOSS = 62,
     * POTENTIAL_SEMEAI_ATTACK = 64, POTENTIAL_SEMEAI_DEFENSE = 66,
     * 
     * ANTISUJI_MOVE = 70,
     */
    ATTACK_MOVE = 1, DEFEND_MOVE = 2, PATTERN_MOVE = 3,

    THREAT = 71, OPEN = 72;

    public static LinkedList<Move> selectTop(LinkedList<Move> movelist)
    {
        boolean sd = false;
        int maxd = 0;

        boolean sa = false;
        int maxa = 0;
        Iterator<Move> iter = movelist.iterator();
        while (iter.hasNext())
        {
            Move m = iter.next();
            if (m.type == PATTERN_MOVE)
            {
                LinkedList<Move> result = new LinkedList<Move>();
                result.add(m);
                return result;
            }
            if (m.type == ATTACK_MOVE)
            {
                sa = true;
                if (maxa < m.num)
                    maxa = m.num;
            }
            if (m.type == DEFEND_MOVE)
            {
                sd = true;
                if (maxd < m.num)
                    maxd = m.num;
            }
        }

        int max = Math.max(maxa, maxd);
        iter = movelist.iterator();
        while (iter.hasNext())
        {
            Move m = iter.next();

            if (sd)
            {
                if (m.type != DEFEND_MOVE || m.num < maxd)
                    iter.remove();
            } else if (sa)
            {
                if (m.type != ATTACK_MOVE || m.num < maxa)
                    iter.remove();
            }
            // if(m.num<max)
            // iter.remove();
        }

        return movelist;
    }
}
